package com.threeti.jiayusms.domain.service.communicationvoice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.threeti.jiayusms.domain.model.CommunicationVoice;
import com.threeti.jiayusms.framework.util.DynaSearchCriteria;
import com.threeti.jiayusms.framework.util.PagedListHandler;
import com.threeti.jiayusms.infrastructure.communicationvoice.CommunicationVoiceDao;
import com.threeti.jiayusms.interfaces.VoiceTemplateDynaCriteriaDto;

@Service
@Transactional(readOnly=true)
public class CommunicationVoiceQueryServiceImpl implements
		CommunicationVoiceQueryService {

	@Autowired
	private CommunicationVoiceDao dao;

	@Override
	public CommunicationVoice findCommunicationVoiceBy(Long voiceId) {
		return dao.loadBy(voiceId, true);
	}
	
	@Override
	public CommunicationVoice findCommunicationVoiceBy(String voiceNo) {
		return dao.loadBy(voiceNo);
	}
	
	@Override
	public PagedListHandler<CommunicationVoice> findAllVoiceTemplatesByPage(int currentPageIndex, int startingIndex) {
    return dao.findAllVoiceTemplatesByPage(currentPageIndex, startingIndex);
	}
	
	@Override
	public PagedListHandler<CommunicationVoice> findVoiceTemplatesByPage(DynaSearchCriteria dynaSearchCriteria, int currentPageIndex, int startingIndex) {
		VoiceTemplateDynaCriteriaDto dynaCriteria = (VoiceTemplateDynaCriteriaDto)dynaSearchCriteria;
		String templateKeywords = dynaCriteria.getTemplateKeywords();
		if (!StringUtils.hasText(templateKeywords)) {//无条件查询
			return dao.findAllVoiceTemplatesByPage(currentPageIndex, startingIndex);
		}
    return dao.findVoiceTemplatesByPage(dynaSearchCriteria, currentPageIndex, startingIndex);
	}
}
